Imports System.IO

Imports Phoenix.DataAccess
Imports Phoenix.Framework

Namespace Helpers

    Public Class ReportHelper
        Private Shared ReadOnly Property EndOfDayReport() As String
            Get
                Return Path.Combine(EnvironmentHelper.ApplicationPath, "Reports/End Of Day Report.xls")
            End Get
        End Property

        Private Shared ReadOnly Property FullSalonReport() As String
            Get
                Return Path.Combine(EnvironmentHelper.ApplicationPath, "Reports/Full Salon Report.xls")
            End Get
        End Property

        Private Shared ReadOnly Property QuickSalonReport() As String
            Get
                Return Path.Combine(EnvironmentHelper.ApplicationPath, "Reports/Quick Salon Report.xls")
            End Get
        End Property


        Public Shared Sub GenerateQuickSalonReport(ByVal fromDate As DateTime, ByVal toDate As DateTime, ByVal path As String)
            Dim ds As QuickReport = AppDataLayer.QuickSalonReport(fromDate, toDate)
            Dim p As QuickReport.Prop = ds.Properties(0)


            p.PrintDate = Now
            p.ReportDate = String.Format("{0:d} - {1:d}", fromDate, toDate)
            p.SalonName = AppConfig.SalonName

            GenerateReport(QuickSalonReport, path, ds.Properties(0), ds)
        End Sub

        Public Shared Sub GenerateEndOfDayReport(ByVal fromDate As DateTime, ByVal path As String)
            Dim sd As Date = fromDate.Date
            Dim ed As Date = sd.AddHours(23).AddMinutes(59).AddSeconds(59)
            Dim ds As EndOfDayReport = AppDataLayer.EndOfDayReport(sd, ed)
            Dim p As EndOfDayReport.Prop = ds.Properties(0)
            Dim n As Date = Now

            p.PrintDate = n.Date
            p.PrintTime = n.TimeOfDay.ToString
            p.ReportDate = fromDate
            p.SalonName = AppConfig.SalonName

            GenerateReport(EndOfDayReport, path, ds.Properties(0), ds)
        End Sub

        Public Shared Sub GenerateFullSalonReport(ByVal fromDate As DateTime, ByVal toDate As DateTime, ByVal path As String)
            Dim ds As FullReport = AppDataLayer.FullSalonReport(fromDate, toDate)
            Dim p As FullReport.Prop = ds.Properties(0)
            Dim n As Date = Now

            p.PrintDate = n.Date
            p.PrintTime = n.TimeOfDay.ToString
            p.ReportDate = String.Format("{0:d} - {1:d}", fromDate, toDate)
            p.SalonName = AppConfig.SalonName

            GenerateReport(FullSalonReport, path, ds.Properties(0), ds)
        End Sub

        Private Shared Sub GenerateReport(ByVal reportPath As String, ByVal savePath As String, ByVal prop As Object, ByVal ds As DataSet)
            Try
                AppReport(reportPath, savePath, prop, ds)

                AppMessageBox(Res.ReportGeneratedMessage, MsgBoxStyle.Information)
            Catch ex As Exception
                Trace.WriteLineIf(AppError, ex)
                AppMessageBox(String.Format(Res.ReportError, ex.Message), MsgBoxStyle.Critical)
            End Try
        End Sub
    End Class

End Namespace
